package org.edu.modules.stu.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.SecurityUtils;
import org.edu.common.base.BasePageDto;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.system.vo.LoginUser;
import org.edu.common.utils.ConvertUtils;
import org.edu.common.base.BaseServiceImpl;
import org.edu.common.utils.DateUtil;
import org.edu.modules.stu.base.mapper.VeStuSemesterMapper;
import org.edu.modules.stu.base.entity.VeStuSemester;
import org.edu.modules.stu.base.dto.VeStuSemesterDto;
import org.edu.modules.stu.base.service.VeStuSemesterService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;



/**
 * 实现类
 */
@Service
public class VeStuSemesterServiceImpl extends BaseServiceImpl<VeStuSemester, VeStuSemesterMapper> implements VeStuSemesterService {

    public IPage<VeStuSemesterDto> pageDto(BasePageDto page, @Param(Constants.WRAPPER) QueryWrapper queryWrapper){
        return mapper.pageDto(page,queryWrapper);
    }
    /**
    * 查询实体类
    */
    public VeStuSemesterDto findDtoById(String id) {
        VeStuSemester entity = super.findById(id);
        VeStuSemesterDto dto = ConvertUtils.convertToDto(entity, VeStuSemesterDto.class);
        return dto;
    }

    /**
    * 新增或者修改
    */
    @Transactional
    public void insertOrUpdate(List<VeStuSemesterDto> dtos,Boolean isAdd){
        for (VeStuSemesterDto dto : dtos) {
            dto.setCreateDate(DateUtil.getNow(DateUtil.TYPE1));
            LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            dto.setCreateBy(sysUser.getId());
            dto.setCreateName(sysUser.getRealname());
            dto.setStatus(1);
            if(dto.getId()==null){
                super.insert(dto);
            }else{
                super.update(dto);
            }
        }
    }

    @Override
    public void importExcel(List<Map<String, Object>> mapList){
        for (Map map: mapList) {
            VeStuSemesterDto dto = new VeStuSemesterDto();
                   //         dto.setSemesterId ((String)map.get(0000));
                   //         dto.setStuId ((String)map.get(0000));
                   //         dto.setStatus ((String)map.get(0000));
                   //         dto.setCreateTime ((String)map.get(0000));
                   //         dto.setCreateUseId ((String)map.get(0000));
                   //         dto.setCancleTime ((String)map.get(0000));
                   //         dto.setCancleUserId ((String)map.get(0000));
            
            super.insert(dto);
        }

    }

}
